package Threads.ReentrantLock;

import java.security.acl.LastOwnerException;
import java.util.concurrent.locks.ReentrantLock;

public class trylockTest {
    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock=new ReentrantLock();
        Thread t1=new Thread(()->{
            boolean b = lock.tryLock();//获取不到锁，返回false
            if (!b){
                System.out.println("fail!");
                return;
            }
            try {
                System.out.println("i got it");
            }finally {
                lock.unlock();
            }
        });

        lock.lock();
        t1.start();
        Thread.sleep(2000);
        lock.unlock();
    }
}
